package lucid.hrms.management.nationality;

import org.apache.commons.lang.StringUtils;
import org.codehaus.grepo.query.commons.aop.QueryMethodParameterInfo;
import org.codehaus.grepo.query.hibernate.generator.CriteriaGenerator;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class NationalityCriteriaGenerator implements CriteriaGenerator {
	public DetachedCriteria generate(QueryMethodParameterInfo qmpi) {
        NationalityCriteria nationalityCriteria = qmpi.getParameterByParamName("nationalityCriteria", NationalityCriteria.class);
        DetachedCriteria criteria = DetachedCriteria.forClass(Nationality.class);
        
        String name = nationalityCriteria.getName();
        if (StringUtils.isNotEmpty(name))
            criteria.add(Restrictions.like("name", name + '%'));
        
        return criteria;
	}
}